import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { stringify } from "qs";
import {
  LoginParamType,
  LoginResultType,
  UserContextResultType,
  ModelList,
  envModel,
  ModeladdInfo,
  ModelSetEnable,
} from "./types";

export * from "./types";

export function login(data: LoginParamType): AxiosPromise<LoginResultType> {
  return request({
    url: `/api/backend/admin/auth/login`,
    method: "post",
    data,
  });
}

export function getUseContext(): AxiosPromise<UserContextResultType> {
  return request({
    url: "/api/backend/admin/auth/get-user-info",
    method: "get",
  });
}

// export function getPermissions(): AxiosPromise {
//   return request({
//     url: "/api/backend/admin/permission/get-permission-list",
//     method: "get",
//   });
// }
// 推出
export function logout() {
  return request({
    url: "/api/Users/logout",
    method: "get",
  });
}

// 获取用户绑定的小程序
export function getAppsList() {
  return request({
    url: "/api/VisibleApp/self",
    method: "get",
  });
}

// 获取分销用户（分销商）列表
export function getAgentList(data: ModelList) {
  return request({
    url: "/api/backend/admin/tenant/get-page",
    method: "post",
    data,
  });
}

// 新增分销用户
export function addTenant(
  data: ModeladdInfo
): AxiosPromise<UserContextResultType> {
  return request({
    url: "/api/backend/admin/tenant/distributor-add",
    method: "post",
    data,
  });
}

// 编辑分销用户
export function updateTenant(
  data: ModeladdInfo
): AxiosPromise<UserContextResultType> {
  return request({
    url: "/api/backend/admin/tenant/update",
    method: "put",
    data,
  });
}

// 查询分销用户详情
export function getTenant(data: number): AxiosPromise<UserContextResultType> {
  return request({
    url: `/api/backend/admin/tenant/get?id=${data}`,
    method: "get",
  });
}

// 设置分销用户启用禁用
export function setEnable(
  data: ModelSetEnable
): AxiosPromise<UserContextResultType> {
  return request({
    url: `/api/backend/admin/tenant/set-enable`,
    method: "post",
    data,
  });
}

// 获取普通用户列表
export function getUserList(
  data: ModelList
): AxiosPromise<UserContextResultType> {
  return request({
    url: "/api/backend/admin/user/get-page",
    method: "post",
    data,
  });
}

// 获取当前环境
export function getEnv(): AxiosPromise<envModel> {
  return request({
    url: "/api/sys/env",
    method: "get",
  });
}
